<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\EmployeePhoto;

/**
 * EmployeePhotoSearch represents the model behind the search form about `common\models\EmployeePhoto`.
 */
class EmployeePhotoSearch extends EmployeePhoto
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'image_width', 'image_height'], 'integer'],
            [['employee_number', 'employee_name', 'image_name', 'image_content_type', 'image_url', 'image_data', 'image_source_url', 'image_source_data', 'memo', 'created_by', 'created_at', 'updated_by', 'updated_at'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = EmployeePhoto::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'image_width' => $this->image_width,
            'image_height' => $this->image_height,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'employee_number', $this->employee_number])
            ->andFilterWhere(['like', 'employee_name', $this->employee_name])
            ->andFilterWhere(['like', 'image_name', $this->image_name])
            ->andFilterWhere(['like', 'image_content_type', $this->image_content_type])
            ->andFilterWhere(['like', 'image_url', $this->image_url])
            ->andFilterWhere(['like', 'image_data', $this->image_data])
            ->andFilterWhere(['like', 'image_source_url', $this->image_source_url])
            ->andFilterWhere(['like', 'image_source_data', $this->image_source_data])
            ->andFilterWhere(['like', 'memo', $this->memo])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by]);

        return $dataProvider;
    }
}
